package br.fot.granola.oboe.util;

import java.nio.ByteBuffer;

public class Vector {
	public float x, y, z;
	
	public Vector()
	{
		x = y = z = 0;
	}
	
	public Vector( float v )
	{
		x = y = z = v;
	}
	
	public Vector( float x, float y, float z )
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public float lengthSquared()
	{
		return this.x*this.x + this.y*this.y + this.z*this.z;
	}
	
	public float length()
	{
		return (float) Math.sqrt(  this.x*this.x + this.y*this.y + this.z*this.z );
	}

	public float distance( Vector v )
	{
		return (float) Math.sqrt(  
				(this.x-v.x)*(this.x-v.x) + 
				(this.y-v.y)*(this.y-v.y) + 
				(this.z-v.z)*(this.z-v.z) );
	}

	public float distanceSquared( Vector v )
	{
		return (  
				(this.x-v.x)*(this.x-v.x) + 
				(this.y-v.y)*(this.y-v.y) + 
				(this.z-v.z)*(this.z-v.z) );
	}

	public Vector rand( float min, float max )
	{
		this.x = (float) Math.random()*(max-min)+min;
		this.y = (float) Math.random()*(max-min)+min;
		this.z = (float) Math.random()*(max-min)+min;
		return this;
	}
	
	public Vector mul( Float v )
	{
		this.x *= v;
		this.y *= v;
		this.z *= v;
		return this;
	}
	
	public Vector add( Vector v )
	{
		this.x += v.x;
		this.y += v.y;
		this.z += v.z;
		return this;
	}
	
	public Vector copy( float v )
	{
		this.x = this.y = this.z = v;
		return this;
	}
	
	public Vector copy( Vector o )
	{
		this.x = o.x;
		this.y = o.y;
		this.z = o.z;
		return this;
	}
	
	public Vector readInt( ByteBuffer b )
	{
		this.x = b.getInt();
		this.y = b.getInt();
		this.z = b.getInt();
		return this;
	}
	
	public Vector readFloat( ByteBuffer b )
	{
		this.x = b.getFloat();
		this.y = b.getFloat();
		this.z = b.getFloat();
		return this;
	}
	
	
}
